package com.itkaien.common;

import com.itkaien.service.SmsService;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

@Component
public class MessageExpirationCheckTask {
    private final RedisTemplate<String, String> redisTemplate;
    private final SmsService smsService;
    public MessageExpirationCheckTask(RedisTemplate<String, String> redisTemplate, SmsService smsService) {
        this.redisTemplate = redisTemplate;
        this.smsService = smsService;
    }
    @Scheduled(fixedRate = 5 * 60 * 1000) // 每五分钟执行一次
    public void checkMessageExpiration() {
        String message = redisTemplate.opsForValue().get("message");
        if (message == null) {
            // 消息已过期，发送短信给管理员
            smsService.sendSmsToAdmin("消息已过期，请及时处理。");
        }
    }
}